# 导包
import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# 打开浏览器
service = Service(r"D://Python314//chromedriver.exe")
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# 放大游览器页面
driver.maximize_window()

# 1.输入用户名；admin1,暂停2秒，删除1
username = driver.find_element(By.CSS_SELECTOR,"#userA").send_keys("admin1")
time.sleep(3)
# 删除1
username.send_keys(Keys.BACK_SPACE)

# 2). 全选用户名：admin，暂停2秒
username.send_keys(Keys.CONTROL, 'a')
time.sleep(3)

# 3). 复制用户名：admin，暂停2秒
username.send_keys(Keys.CONTROL, 'c')
time.sleep(3)

# 4). 粘贴到密码框
# 定位到密码框，执行Ctrl+v
# assword = driver.find_element_by_css_selector("#passwordA")
password = driver.find_element(By.CSS_SELECTOR,"#passwordA")
password.send_keys(Keys.CONTROL, 'v')

